QzxxPanel = function(){
    
    this.grid = new QzHouseGrid(this, {
    });
    
    var qzxxTplMarkup = [
        '<font color="green">【{khxm}】</font> <font color="red">{khdh}</font><br/>',
        '【面积:】{cf_min} - {cf_max}<br/>',
        '【描述:】 {bz}<br/><br/>',
        '{ygbm}: {ygxm} [{create_at:date("Y-m-d")}委托]<br/>'
    ];
    
    var qzxxTpl = new Ext.Template(qzxxTplMarkup);
    
    
    
    var add_qzxx = function(gsm) {
      
      if (gsm != undefined) { //编辑
        
        if (currentUser.prev_code[7] != 't') {
          //  Ext.Msg.alert('Message','权限不够. 请与管理员联系后再试！');
          //  return;
        }
      } else { // 新增              
        if (currentUser.prev_code[5] != 't') {
            Ext.Msg.alert('Message','权限不够. 请与管理员联系后再试！');
            return;
        }
      }
      
      bm_store.load();
      var test_win = new Ext.Window({
          title: '增加客源',
          floating: true,
          shadow: true,
          draggable: true,
          closable: true,
          modal: true,
          width: 700,
          height: 513,
          layout: 'fit',
          plain: true,
          items: [{
                xtype: 'form',
                width: 668,
                height: 513,
                layout: 'absolute',
                id : 'qzxx_add_form',
                defaults: {      // defaults applied to items
                    layout: 'absolute'
                    //border: false,
                    //bodyStyle: 'padding:5px'
                    //y: -10
                },
                items: [{
                        xtype: 'fieldset',
                        layout: 'absolute',
                        width: 665,
                        height: 135,
                        y: 0,
                        padding: 0,
                        items: [
                            {
                                xtype: 'label',
                                text: '客源编号',
                                x: 430,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '等级',
                                x: 430,
                                y: 30
                            },
                            {
                                xtype: 'label',
                                text: '现住',
                                x: 540,
                                y: 30
                            },
                            {
                                xtype: 'label',
                                text: '意向',
                                x: 540,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '期限',
                                x: 540,
                                y: 90
                            },
                            {
                                xtype: 'label',
                                text: '类别',
                                x: 430,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '国籍',
                                x: 430,
                                y: 90
                            },
                            {
                                xtype: 'label',
                                text: '客户',
                                x: 10,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '联系人',
                                x: 0,
                                y: 30
                            },
                            {
                                xtype: 'label',
                                text: '身份证',
                                x: 0,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '现住址',
                                x: 0,
                                y: 90
                            },
                            {
                                xtype: 'label',
                                text: '手机',
                                x: 210,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '联系',
                                x: 210,
                                y: 30
                            },
                            {
                                xtype: 'textfield',
                                width: 150,
                                name: 'khxm',
                                x: 40,
                                y: 0
                            },
                          /*  {
                                xtype: 'button',
                                text: '+',
                                x: 170,
                                y: 30,
                                width: 20,
                                handler: function() {
                                  add_lxr();
                                }
                            }, */
                            {
                                xtype: 'textfield',
                                width: 160,
                                name: 'khdh',
                                x: 240,
                                y: 0,
                                listeners:{
                                  scope: this,
                                  'blur': function(field){
                                    if (field.getValue() != field.startValue){
                                      var pars = {mobile:field.getValue()};
                                      new Ajax.Request("/desktop/check_khxx_mobile", 
                                        { method: "POST",
                                          parameters: pars,
                                          onComplete:  function(request) {
                                            var users = eval("("+request.responseText+")");
                                            if (users.size() > 0) {
                                              
                                              Ext.Msg.confirm("确认", "用户已经存在,确定使用？", 
                                                function(btn){
                                                  if (btn=='yes') {
                                                    select = users[0].users;
                                                    var qz_form = Ext.getCmp('qzxx_add_form').form;
                                                    qz_form.findField('kh_id').setValue(select['id']);
                                                    qz_form.findField('khxm').setValue(select['gsmc']);
                                                    qz_form.findField('khlxr').setValue(select['lxr']);
                                                    qz_form.findField('khsfz').setValue(select['khsfz']);
                                                    qz_form.findField('khdh').setValue(select['mobile']);
                                                    qz_form.findField('khdz').setValue(select['address']);                                          
                                                  }
                                                  else {
                                                    field.startValue='';
                                                    field.setValue('');
                                                  }
                                                }
                                              );
                                              
                                            } 
                                          }
                                        });
                                    }
                                  }
                                }
                            },
                            {
                                xtype: 'textfield',
                                width: 150,
                                name: 'khlxr',
                                x: 40,
                                y: 30
                            },
                            {
                                xtype: 'textfield',
                                width: 150,
                                name: 'khsfz',
                                x: 40,
                                y: 60
                            },
                            {
                                xtype: 'textfield',
                                width: 150,
                                name: 'khdz',
                                x: 40,
                                y: 90
                            },
                            {
                                xtype: 'textarea',
                                width: 160,
                                height: 80,
                                x: 240,
                                y: 30,
                                name: 'lxfs'
                            },
                            {
                                xtype: 'textfield',
                                width: 160,
                                name: 'kybh',
                                x: 480,
                                y: 0
                            },
                            {
                                xtype: 'combo',
                                x: 460,
                                y: 30,
                                name: 'khdj',
                                width: 70,
                                store: khjb_store,
                                emptyText:'',
                                mode: 'remote',
                                minChars : 2,
                                valueField:'value',
                                displayField:'value',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 570,
                                y: 30,
                                name: 'khxz',
                                width: 70,
                                store: khxz_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 460,
                                y: 60,
                                width: 70,
                                name: 'khlb',
                                store: khlb_store,
                                emptyText:'',
                                mode: 'remote',
                                minChars : 2,
                                valueField:'value',
                                displayField:'value',
                                triggerAction:'all',
                                value:'求租客户'        
                            },
                            {
                                xtype: 'combo',
                                x: 570,
                                y: 60,
                                name: 'qzyx',
                                width: 70,
                                store: khyx_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'           
                            },
                            {
                                xtype: 'combo',
                                x: 460,
                                y: 90,
                                name: 'khgj',
                                width: 70,
                                store: gj_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 570,
                                y: 90,
                                name: 'khqx',
                                width: 70,
                                store: khqx_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            }
                        ]
                    },
                    {
                        xtype: 'fieldset',
                        layout: 'absolute',
                        width: 432,
                        height: 165,
                        y: 134,
                        x: 0,
                        items: [
                            {
                                xtype: 'combo',
                                x: 40,
                                y: 0,
                                width: 80,
                                name: 'jy',
                                store: qz_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'value',
                                displayField:'text',
                                triggerAction:'all',
                                value:'求租'
                            },
                            {
                                xtype: 'combo',
                                x: 155,
                                y: 0,
                                width: 80,
                                name: 'zt',
                                store: zt_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all',
                                value:'有效'
                            },
                            {
                                xtype: 'combo',
                                x: 40,
                                y: 30,
                                width: 80,
                                name: 'cq',
                                store: qy_store,
                                emptyText:'',
                                mode: 'remote',
                                minChars : 2,
                                valueField:'value',
                                displayField:'value',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 120,
                                y: 30,
                                width: 80,
                                hidden: true,
                                name: 'pq'
                            },
                            {
                                xtype: 'textfield',
                                x: 120,
                                y: 30,
                                width: 290,
                                name: 'mpdh'
                            },
                            {
                                xtype: 'label',
                                text: '地址',
                                x: 10,
                                y: 30
                            },
                            {
                                xtype: 'label',
                                text: '交易',
                                x: 10,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '员工',
                                x: 10,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '厂房',
                                x: 10,
                                y: 90
                            },
                            {
                                xtype: 'label',
                                text: '价格',
                                x: 10,
                                y: 120
                            },
                            {
                                xtype: 'label',
                                text: '-',
                                x: 110,
                                y: 90,
                                width: 20
                            },
                            {
                                xtype: 'label',
                                text: '-',
                                x: 110,
                                y: 120,
                                width: 20
                            },
                            {
                                xtype: 'label',
                                text: '平米',
                                x: 180,
                                y: 90,
                                width: 30
                            },
                            {
                                xtype: 'label',
                                text: '元',
                                x: 180,
                                y: 120,
                                width: 30
                            },
                            {
                                xtype: 'label',
                                text: '委托',
                                x: 230,
                                y: 90,
                                width: 30
                            },
                            {
                                xtype: 'label',
                                text: '来源',
                                x: 230,
                                y: 120,
                                width: 30
                            },
                            {
                                xtype: 'label',
                                text: '状态',
                                x: 130,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '宿舍',
                                x: 120,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '办公',
                                x: 220,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '空地',
                                x: 320,
                                y: 60
                            },
                            {
                                xtype: 'checkbox',
                                x: 260,
                                y: 0,
                                boxLabel: '自行',
                                name: 'gs'
                            },
                            {
                                xtype: 'checkbox',
                                x: 310,
                                y: 0,
                                boxLabel: '已签合同',
                                name: 'yzk'
                            },
                            {
                                xtype: 'button',
                                x: 380,
                                y: 0,
                                width: 20,
                                xtype: 'button',
                                text: '合同',
                                handler: function() {
                                
                                }
                            },
                            {
                                xtype: 'container',
                                x: 375,
                                y: -10,
                                width: 30,
                                height: 30,
                                autoEl: '租'
                            },
                            {
                                xtype: 'textfield',
                                x: 40,
                                y: 60,
                                width: 60,
                                name: 'ygmj',
                                value: '0'
                            },
                            {
                                xtype: 'textfield',
                                x: 150,
                                y: 60,
                                width: 60,
                                name: 'ssmj',
                                value: '0'
                            },
                            {
                                xtype: 'textfield',
                                x: 250,
                                y: 60,
                                width: 60,
                                name: 'bgmj',
                                value: '0'
                            },
                            {
                                xtype: 'textfield',
                                x: 350,
                                y: 60,
                                width: 60,
                                name: 'kdmj',
                                value: '0'
                            },
                            {
                                xtype: 'textfield',
                                x: 40,
                                y: 90,
                                width: 60,
                                name: 'cf_min',
                                value: '0'
                            },
                            {
                                xtype: 'textfield',
                                x: 120,
                                y: 90,
                                width: 60,
                                name: 'cf_max',
                                value: '1000'
                            },
                            {
                                xtype: 'textfield',
                                x: 40,
                                y: 120,
                                width: 60,
                                name: 'jg_min',
                                value: '0'
                            },
                            {
                                xtype: 'textfield',
                                x: 120,
                                y: 120,
                                width: 60,
                                name: 'jg_max',
                                value: '10'
                            },
                            {
                                xtype: 'datefield',
                                x: 260,
                                y: 90,
                                width: 150,
                                format:'Y-m-d',
                                name: 'create_at',
                                value: (new Date()).format('Y-m-d')
                            },
                            {
                                xtype: 'combo',
                                x: 260,
                                y: 120,
                                width: 70,
                                name: 'wtfs',
                                store: xxly_store,
                                emptyText:'',
                                mode: 'remote',
                                valueField:'value',
                                displayField:'value',
                                triggerAction:'all'                               
                            },
                            {
                                xtype: 'combo',
                                x: 340,
                                y: 120,
                                width: 70,
                                name: 'wtly',
                                store: wtly_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            }
                        ]
                    },
                    {
                        xtype: 'label',
                        text: '备注',
                        x: 440,
                        y: 280
                    },
                    {
                        xtype: 'label',
                        text: '部门',
                        x: 440,
                        y: 400
                    },
                    {
                        xtype: 'fieldset',
                        x: 431,
                        y: 134,
                        height: 135,
                        width: 234,
                        layout: 'absolute',
                        items: [
                            {
                                xtype: 'label',
                                text: '用途',
                                x: 0,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '类型',
                                x: 0,
                                y: 30
                            },
                            {
                                xtype: 'label',
                                text: '围墙',
                                x: 0,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '配套',
                                x: 0,
                                y: 90
                            },
                            {
                                xtype: 'label',
                                text: '电量',
                                x: 110,
                                y: 0
                            },
                            {
                                xtype: 'label',
                                text: '层数',
                                x: 110,
                                y: 30
                            },
                            {
                                xtype: 'label',
                                text: '租金',
                                x: 110,
                                y: 60
                            },
                            {
                                xtype: 'label',
                                text: '付佣',
                                x: 110,
                                y: 90
                            },
                            {
                                xtype: 'combo',
                                x: 30,
                                y: 0,
                                width: 70,
                                name: 'yt',
                                store: yt_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'textfield',
                                x: 140,
                                y: 0,
                                width: 70,
                                name: 'dgl',
                                value: '0'
                            },
                            {
                                xtype: 'combo',
                                x: 30,
                                y: 30,
                                width: 70,
                                name: 'lx',
                                store: lx_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 140,
                                y: 30,
                                width: 70,
                                name: 'cs',
                                store: cs_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 30,
                                y: 60,
                                width: 70,
                                name: 'fwwq',
                                store: fwwq_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 140,
                                y: 60,
                                width: 70,
                                name: 'czfs',
                                store: czfs_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            },
                            {
                                xtype: 'combo',
                                x: 30,
                                y: 90,
                                width: 70,
                                name: 'fwpt',
                                store: pt_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'           
                            },
                            {
                                xtype: 'combo',
                                x: 140,
                                y: 90,
                                width: 70,
                                name: 'fyfs',
                                store: fy_store,
                                emptyText:'',
                                mode: 'local',
                                valueField:'text',
                                displayField:'text',
                                triggerAction:'all'
                            }
                        ]
                    },
                    {
                        xtype: 'textarea',
                        x: 470,
                        y: 280,
                        width: 180,
                        height: 110,
                        name: 'bz'
                    },
                    {
                        xtype: 'combo',
                        x: 470,
                        y: 400,
                        width: 90,
                        name: 'ygbm',
                        store: bm_store,
                        emptyText:'',
                        mode: 'local',
                        valueField:'text',
                        displayField:'text',
                        triggerAction:'all',
                        listeners:{
                          scope: this,
                          'select': function(combo){
                            yg_store.baseParams={bm:combo.getValue()};
                            yg_store.load();
                          }
                        }
                    },
                    {
                        xtype: 'combo',
                        x: 560,
                        y: 400,
                        width: 90,
                        name: 'ygxm',
                        store: yg_store,
                        emptyText:'',
                        mode: 'local',
                        valueField:'text',
                        displayField:'text'
                    },
                    {
                      xtype: 'textfield',
                      hidden : true,
                      name : 'id'                     
                    },
                    {
                        xtype: 'textfield',
                        hidden : true,
                        name : 'kh_id'
                    },
                    {
                        xtype: 'textfield',
                        hidden : true,
                        name : 'yg_id'                      
                    },
                    {
                        xtype: 'fieldset',
                        title: '',
                        x: 0,
                        y: 298,
                        width: 432,
                        height: 140
                    },
                    {
                      layout:"absolute",
                      xtype: 'grid',
                      x: 10,
                      y: 310,
                      id: 'qzxx_gj_grid',
                      width: 410,
                      height : 120,
                      stripeRows: true,
                      store: Ext.getCmp('qzxx-view').qzgjStore,
                      columns: [
                         // {id:'id',header: 'id', width: 20, hidden: true, dataIndex: 'id', sortable: true},
                         {header: '跟进信息',   width: 200, height:50, sortable: true, dataIndex: 'message'},
                         {header: '部门',     width: 50, sortable: true,  dataIndex: 'ygbm'},
                         {header: '跟进人',    width: 50, sortable: true,  dataIndex: 'ygxm'},
                         {header: '最后更新日期', width: 100, sortable: true,  renderer: Ext.util.Format.dateRenderer('Y-m-d'), dataIndex: 'create_at'}
                      ],
                      viewConfig: {
                          forceFit:true,
                          enableRowBody:true,
                          showPreview : true,
                          getRowClass : function(record, rowIndex, p, ds) {
                              if (this.showPreview) {
                                  var xf = Ext.util.Format;
                                  p.body = '<p>' + xf.ellipsis(xf.stripTags(record.data.message), 200) + '</p>';
                                  return 'x-grid3-row-expanded';
                              }
                              return 'x-grid3-row-collapsed';
                          }
                      }
                    },
                    {
                      layout:"absolute",
                      xtype: 'grid',
                      x: 10,
                      y: 310,
                      id: 'qzxx_dk_grid',
                      width: 410,
                      height : 120,
                      stripeRows: true,
                      store: Ext.getCmp('qzxx-view').dkgjStore,
                      columns: [
                         // {id:'id',header: 'id', width: 20, hidden: true, dataIndex: 'id', sortable: true},
                         {header: '带看信息',   width: 150, sortable: true, dataIndex: 'message'},
                         {header: '带看人',    width: 50, sortable: true,  dataIndex: 'yg_xm'},
                         {header: '客户',     width: 50, sortable: true,  dataIndex: 'qz_xm'},
                         {header: '接待人',    width: 50, sortable: true,  dataIndex: 'cz_xm'},
                         {header: '带看合同',   width: 50, sortable: true,  dataIndex: 'dkht'},
                         {header: '带看时间',   width: 100, sortable: true,  renderer: Ext.util.Format.dateRenderer('Y-m-d'), dataIndex: 'visit_at'}
                      ]
                }],
            buttons:[
            {
              text: '写跟进',
              handler: function(){
                var text = Ext.getCmp('qzxx_add_form').buttons[0].getText();
                if (text == '写跟进') {
                  action2.execute();
                } else if (text == '写带看'){
                  action6.execute();
                }
              }
            },
            {
              text: '删除',
              handler: function(){
                var text = Ext.getCmp('qzxx_add_form').buttons[0].getText();
                if (text == '写跟进') {
                  var data = Ext.getCmp('qzxx_gj_grid').getSelectionModel().getSelected().data;
                  var pars={id:data.id}
                  new Ajax.Request("/desktop/delete_qzgj", 
                    { method: "POST",
                      parameters: pars,
                      onComplete:  function(request) {
                        Ext.getCmp('qzxx_gj_grid').store.reload();
                      }
                    });
                } else if  (text == '写带看') {
                  var data = Ext.getCmp('qzxx_dk_grid').getSelectionModel().getSelected().data;
                  var pars={id:data.id}
                  new Ajax.Request("/desktop/delete_dkgj", 
                    { method: "POST",
                      parameters: pars,
                      onComplete:  function(request) {
                        Ext.getCmp('qzxx_dk_grid').store.reload();
                      }
                    });
                }                 
              }
            },
            {
              text: '切换',
              handler: function(){
                if ( Ext.getCmp('qzxx_gj_grid').isVisible() ){
                  Ext.getCmp('qzxx_gj_grid').hide();
                  Ext.getCmp('qzxx_dk_grid').show();
                  Ext.getCmp('qzxx_add_form').buttons[0].show();
                  Ext.getCmp('qzxx_add_form').buttons[1].show();
                  Ext.getCmp('qzxx_add_form').buttons[0].setText('写带看')   
                } else {
                  Ext.getCmp('qzxx_gj_grid').show();
                  Ext.getCmp('qzxx_dk_grid').hide();
                  Ext.getCmp('qzxx_add_form').buttons[0].show();
                  Ext.getCmp('qzxx_add_form').buttons[1].show();        
                  Ext.getCmp('qzxx_add_form').buttons[0].setText('写跟进')   
                }
              }             
            },
            {
              text: '上一个',
              handler: function(){
                gsm.selectPrevious();
                var data = gsm.getSelected();
                var form = Ext.getCmp("qzxx_add_form").getForm();
                form.loadRecord(data);                
              }
            },
            {
              text: '下一个',
              handler: function(){
                gsm.selectNext();
                var data = gsm.getSelected();
                var form = Ext.getCmp("qzxx_add_form").getForm();
                form.loadRecord(data);                
              }
            },
            {
              text: '保存',
              handler: function(){
                var pars = Ext.getCmp("qzxx_add_form").getForm().getValues();
                new Ajax.Request("/desktop/save_qzxx", 
                  { method: "POST",
                    parameters: pars,
                    onComplete:  function(request) {
                      //test_win.close();
                      Ext.getCmp('grid-house1').show();
                      
                      //reload 
                      if (gsm != undefined) {
                        gsm.grid.store.reload();
                        gsm.selectRow(gsm.grid.store.indexOfId(qzxx_id), true);
                      } else {
                        test_win.close();
                        Ext.getCmp('qzxx-view').gsm.grid.store.reload();
                      } 
                    }
                  });
              }
            },{
              text: '取消',
              handler: function(){
                test_win.close();
                Ext.getCmp('grid-house1').show();
              }
            }]
          }]
      });

      test_win.on('close', function(){
        Ext.getCmp('grid-house1').show();
      });

      if (gsm != undefined) {
        
        
        var data = gsm.getSelected();
        var form = Ext.getCmp("qzxx_add_form").getForm();
        form.loadRecord(data);
        
        if (currentUser.prev_code[7] == 't') 
          test_win.setTitle('修改客源 - '+data.data.khxm)
        else 
          test_win.setTitle('查看客源 - '+data.data.khxm);
        
        test_win.setIconClass('new');
        Ext.getCmp('qzxx_add_form').buttons[0].show();
        Ext.getCmp('qzxx_add_form').buttons[1].show();
        
        //hide save button
        if (currentUser.prev_code[7] != 't') {
          Ext.getCmp('qzxx_add_form').buttons[5].hide();
        }
        
        Ext.getCmp('qzxx_dk_grid').hide();
      } else {
        
        
        var data = {};
        data['yg_id'] = currentUser['id'];
        data['ygxm'] = currentUser['login'];
        data['ygbm'] = currentUser['bm'];
        var form = Ext.getCmp("qzxx_add_form").getForm();
        form.setValues(data);   
        test_win.setTitle('新增客源');
        test_win.setIconClass('add2');
        Ext.getCmp('qzxx_add_form').buttons[0].hide();
        Ext.getCmp('qzxx_add_form').buttons[1].hide();  
        Ext.getCmp('qzxx_add_form').buttons[2].hide();
        Ext.getCmp('qzxx_add_form').buttons[3].hide();
        Ext.getCmp('qzxx_add_form').buttons[4].hide();
        Ext.getCmp('qzxx_gj_grid').hide();  
        Ext.getCmp('qzxx_dk_grid').hide();
      }
      //Ext.getCmp('grid-house1').hide();
      test_win.show();
      test_win.setZIndex(9020);       
    };
    
    var action1 = new Ext.Action({
        text: '看详细',
        handler: function(){
            add_qzxx(Ext.getCmp('qzxx-view').gsm);  
        }
        //iconCls: 'blist'
    });

    var action2 = new Ext.Action({
        text: '写跟进',
        handler: function(){
            //msg('Click','You clicked on "写跟进".');
            var track_win = new Ext.Window({
                title: '写跟进',
                floating: true,
                shadow: true,
                draggable: true,
                closable: true,
                modal: true,
                width: 430,
                height: 360,
                layout: 'fit',
                plain: true,
                items: [{
                  xtype:"form",
                  id : 'qz_track_win_form',
                  width: 422,
                  height: 326,
                  padding: 10,
                  layout: 'absolute',
                  items:[
                      {
                          xtype: 'label',
                          text: '时间方式',
                          x: 20,
                          y: 10
                      },
                      {
                          xtype: 'label',
                          text: '部门员工',
                          x: 20,
                          y: 40
                      },
                      {
                          xtype: 'label',
                          text: '跟进内容',
                          x: 20,
                          y: 70
                      },
                      {
                          xtype: 'label',
                          text: '下次提醒',
                          x: 20,
                          y: 180
                      },
                      {
                          xtype: 'label',
                          text: '提醒范围',
                          x: 20,
                          y: 210
                      },
                      {
                          xtype: 'label',
                          text: '提醒内容',
                          x: 20,
                          y: 240
                      },
                      {
                          xtype: 'datefield',
                          x: 90,
                          y: 10,
                          name: 'sjfs',
                          format:"Y-m-d",
                          emptyText:'(系统时间)',
                          width:150
                      },
                      {
                          xtype: 'textfield',
                          x: 90,
                          y: 40,
                          name: 'bmyg',
                          value: currentUser.login,
                          width:150
                      },
                      {
                          xtype: 'textarea',
                          x: 90,
                          y: 70,
                          anchor: '',
                          width: 300,
                          height: 100,
                          name: 'gjnr'
                      },
                      {
                          xtype: 'datefield',
                          x: 90,
                          y: 180,
                          width: 100,
                          name: 'gjrq',
                          format:"Y-m-d",
                          value: (new Date()).format('Y-m-d')
                      },
                      {
                          xtype: 'timefield',
                          x: 200,
                          y: 180,
                          width: 80,
                          minValue: '9:00 AM',
                          maxValue: '6:00 PM',
                          increment: 30,
                          name: 'gjsj',
                          value: (new Date()).format('H:i A')
                      },
                      {
                          xtype: 'combo',
                          x: 90,
                          y: 210,
                          name: 'txfw',
                          mode  : "local", 
                          store : txfw_store,
                          displayField: 'text', 
                          valueField: 'text',
                          triggerAction : 'all',
                          emptyText : '',
                          value: '不提醒',
                          width:150
                      },
                      {
                          xtype: 'textfield',
                          x: 90,
                          y: 240,
                          width: 300,
                          name: 'txnr'
                      }
                  ],
                  buttons:[{
                    text: '保存',
                    handler: function(){
                      var pars = Ext.getCmp("qz_track_win_form").getForm().getValues();
                      pars['yg_id']=currentUser.id;
                      pars['ygbm']=currentUser.bm;
                      pars['ygxm']=currentUser.login;
                      pars['qzxx_id']=qzxx_id;
                      var now = new Date();
                      pars['create_at']=now.format('Y-m-d H:i:s');
                      
                      new Ajax.Request("/desktop/add_qzgj", { 
                        method: "POST",
                        parameters: pars,
                        onComplete:  function(request) {
                          track_win.close();
                          
                          //reload track window
                          Ext.getCmp('qzxx-view').qzgjStore.baseParams = {id:qzxx_id}
                          Ext.getCmp('qzxx-view').qzgjStore.load();
                        }
                      });
                    }
                  },{
                    text: '取消',
                    handler: function(){
                      track_win.close();
                    }
                  }]
                }]
            });
            
            track_win.show();
            track_win.setZIndex(9020);  
            /*
            var pars = {user:user_id};
            new Ajax.Request("/desktop/set_track", { 
              method: "POST",
              parameters: pars,
              onComplete:  function(request) {
                var user = eval("("+request.responseText+")")[0].users;
                Ext.getCmp("cz_track_win_form").getForm().setValues(user);

                //show the window
                //track_win.show();
              }
            });
            */
        }
        //iconCls: 'blist'
    });

    var action3 = new Ext.Action({
        text: '看客户',
        handler: function(){
            //msg('Click','You clicked on "写跟进".');
            var track_win = new Ext.Window({
                title: '客户信息',
                floating: true,
                shadow: true,
                draggable: true,
                closable: true,
                modal: true,
                width: 518,
                height: 395,
                layout: 'fit',
                plain: true,
                items: [{
                  xtype:"form",
                  id : 'customer_add_form',
                  width: 518,
                  height: 395,
                  padding: 10,
                  layout: 'absolute',
                  items:[{
                      xtype: 'tabpanel',
                      deferredRender: false,
                      activeTab: 0,
                      width: 500,
                      height: 320,
                      items: [
                          {
                              xtype: 'panel',
                              title: '客户信息',
                              layout: 'absolute',
                              width: 536,
                              height: 409,
                              items: [
                                  {
                                      xtype: 'textfield',
                                      hidden : true,
                                      name : 'id'
                                  },
                                  {
                                      xtype: 'label',
                                      text: '客户编号',
                                      x: 20,
                                      y: 10
                                  },
                                  {
                                      xtype: 'label',
                                      text: '联系人',
                                      x: 20,
                                      y: 40
                                  },
                                  {
                                      xtype: 'label',
                                      text: '职位',
                                      x: 20,
                                      y: 70
                                  },
                                  {
                                      xtype: 'label',
                                      text: '行业',
                                      x: 20,
                                      y: 100
                                  },
                                  {
                                      xtype: 'label',
                                      text: '移动电话',
                                      x: 20,
                                      y: 130
                                  },
                                  {
                                      xtype: 'label',
                                      text: 'iPhone',
                                      x: 20,
                                      y: 160
                                  },
                                  {
                                      xtype: 'label',
                                      text: '小灵通',
                                      x: 20,
                                      y: 190
                                  },
                                  {
                                      xtype: 'label',
                                      text: '家庭电话',
                                      x: 20,
                                      y: 220
                                  },
                                  {
                                      xtype: 'label',
                                      text: '其他电话',
                                      x: 20,
                                      y: 250
                                  },
                                  {
                                      xtype: 'label',
                                      text: '客户类别',
                                      x: 260,
                                      y: 10
                                  },
                                  {
                                      xtype: 'label',
                                      text: '电子邮件',
                                      x: 260,
                                      y: 40
                                  },
                                  {
                                      xtype: 'label',
                                      text: '生日',
                                      x: 260,
                                      y: 70
                                  },
                                  {
                                      xtype: 'label',
                                      text: '个人爱好',
                                      x: 260,
                                      y: 100
                                  },
                                  {
                                      xtype: 'label',
                                      text: '子女情况',
                                      x: 260,
                                      y: 130
                                  },
                                  {
                                      xtype: 'label',
                                      text: '家庭地址',
                                      x: 260,
                                      y: 160
                                  },
                                  {
                                      xtype: 'label',
                                      text: '备注',
                                      x: 260,
                                      y: 190
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 10,
                                      width: 150,
                                      name: 'khbh'
                                  },
                                  {
                                      xtype: 'combo',
                                      x: 320,
                                      y: 10,
                                      width: 150,
                                      name: 'khlb',
                                      store: khlb_store,
                                      emptyText:'',
                                      mode: 'remote',
                                      minChars : 2,
                                      valueField:'value',
                                      displayField:'value',
                                      triggerAction:'all'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 40,
                                      width: 150,
                                      name: 'lxr'
                                  },
                                  {
                                      xtype: 'combo',
                                      x: 80,
                                      y: 70,
                                      width: 150,
                                      name: 'zw',
                                      store: zwbh_store,
                                      emptyText:'',
                                      mode: 'remote',
                                      minChars : 2,
                                      valueField:'value',
                                      displayField:'value',
                                      triggerAction:'all'                 
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 100,
                                      width: 150,
                                      name: 'hy'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 130,
                                      width: 150,
                                      name: 'mobile'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 160,
                                      width: 150,
                                      name: 'iphone'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 190,
                                      width: 150,
                                      name: 'linktone'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 220,
                                      width: 150,
                                      name: 'jtdh1'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 250,
                                      width: 150,
                                      name: 'jtdh2'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 320,
                                      y: 40,
                                      width: 150,
                                      name: 'email'
                                  },
                                  {
                                      xtype: 'datefield',
                                      x: 320,
                                      y: 70,
                                      width: 150,
                                      format: 'Y-m-d',
                                      name: 'birthday'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 320,
                                      y: 100,
                                      width: 150,
                                      name: 'hobby'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 320,
                                      y: 130,
                                      width: 150,
                                      name: 'children'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 320,
                                      y: 160,
                                      width: 150,
                                      name: 'jtdz'
                                  },
                                  {
                                      xtype: 'textarea',
                                      x: 320,
                                      y: 190,
                                      width: 150,
                                      anchor: '',
                                      height: 80,
                                      name: 'bz'
                                  }
                              ]
                          },
                          {
                              xtype: 'panel',
                              title: '公司信息',
                              layout: 'absolute',
                              items: [
                                  {
                                      xtype: 'label',
                                      text: '公司名称',
                                      x: 20,
                                      y: 10
                                  },
                                  {
                                      xtype: 'label',
                                      text: '公司规模',
                                      x: 20,
                                      y: 40
                                  },
                                  {
                                      xtype: 'label',
                                      text: '公司全名',
                                      x: 20,
                                      y: 70
                                  },
                                  {
                                      xtype: 'label',
                                      text: '电话1',
                                      x: 20,
                                      y: 100
                                  },
                                  {
                                      xtype: 'label',
                                      text: '电话2',
                                      x: 20,
                                      y: 130
                                  },
                                  {
                                      xtype: 'label',
                                      text: '传真',
                                      x: 20,
                                      y: 160
                                  },
                                  {
                                      xtype: 'label',
                                      text: '网址',
                                      x: 20,
                                      y: 190
                                  },
                                  {
                                      xtype: 'label',
                                      text: '地址',
                                      x: 20,
                                      y: 220
                                  },
                                  {
                                      xtype: 'label',
                                      text: '邮编',
                                      x: 20,
                                      y: 250
                                  },
                                  {
                                      xtype: 'label',
                                      text: '开户银行',
                                      x: 260,
                                      y: 10
                                  },
                                  {
                                      xtype: 'label',
                                      text: '银行账号',
                                      x: 260,
                                      y: 40
                                  },
                                  {
                                      xtype: 'label',
                                      text: '税务登记号',
                                      x: 260,
                                      y: 70
                                  },
                                  {
                                      xtype: 'label',
                                      text: '所有制类型',
                                      x: 260,
                                      y: 100
                                  },
                                  {
                                      xtype: 'label',
                                      text: '客户级别',
                                      x: 260,
                                      y: 130
                                  },
                                  {
                                      xtype: 'label',
                                      text: '金土地内评',
                                      x: 260,
                                      y: 160
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 10,
                                      width: 150,
                                      name: 'gsmc'
                                  },
                                  {
                                      xtype: 'combo',
                                      x: 80,
                                      y: 40,
                                      width: 150,
                                      name: 'gsgm',
                                      store: gsgm_store,
                                      emptyText:'',
                                      mode: 'remote',
                                      minChars : 2,
                                      valueField:'value',
                                      displayField:'value',
                                      triggerAction:'all'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 70,
                                      width: 150,
                                      name: 'gsqm'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 100,
                                      width: 150,
                                      name: 'bgdh1'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 130,
                                      width: 150,
                                      name: 'bgdh2'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 160,
                                      width: 150,
                                      name: 'bgcz'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 190,
                                      width: 150,
                                      name: 'gsweb'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 220,
                                      width: 150,
                                      name: 'address'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 80,
                                      y: 250,
                                      width: 150,
                                      name: 'zip'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 330,
                                      y: 10,
                                      width: 150,
                                      name: 'khyh'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 330,
                                      y: 40,
                                      width: 150,
                                      name: 'yhzh'
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 330,
                                      y: 70,
                                      width: 150,
                                      name: 'swdjh'
                                  },
                                  {
                                      xtype: 'combo',
                                      x: 330,
                                      y: 100,
                                      width: 150,
                                      name: 'syzlx',
                                      store: syzlx_store,
                                      emptyText:'',
                                      mode: 'remote',
                                      minChars : 2,
                                      valueField:'value',
                                      displayField:'value',
                                      triggerAction:'all'                 
                                  },
                                  {
                                      xtype: 'combo',
                                      x: 330,
                                      y: 130,
                                      width: 150,
                                      name: 'khjb',
                                      store: khjb_store,
                                      emptyText:'',
                                      mode: 'remote',
                                      minChars : 2,
                                      valueField:'value',
                                      displayField:'value',
                                      triggerAction:'all'                 
                                  },
                                  {
                                      xtype: 'textfield',
                                      x: 330,
                                      y: 160,
                                      width: 150,
                                      name: 'jtdnp'
                                  }
                              ]
                          }
                      ]
                  }],
                  buttons:[{
                    text: '保存',
                    handler: function(){
                      var pars = Ext.getCmp("customer_add_form").getForm().getValues();
                      pars['qzxx_id']=qzxx_id;

                      new Ajax.Request("/desktop/add_customer", { 
                        method: "POST",
                        parameters: pars,
                        onComplete:  function(request) {
                          track_win.close();
                        }
                      });
                    }
                  },{
                    text: '取消',
                    handler: function(){
                      track_win.close();
                    }
                  }]
                }]
            });
            
            var pars = {qzxx_id:qzxx_id};
            new Ajax.Request("/desktop/set_customer", { 
              method: "POST",
              parameters: pars,
              onComplete:  function(request) {
                var users = eval("("+request.responseText+")");
                if (users.size() > 0) {
                  Ext.getCmp("customer_add_form").getForm().setValues(users[0].users);
                } 
                
                //show the window
                //track_win.show();
              }
            });
            
            track_win.show();           
        }
        //iconCls: 'blist'
    });

    var action5 = new Ext.Action({
        text: '看带看',
        handler: function(){
          //czgj-grid
          if (dkgjGrid.isVisible()) {
            dkgjGrid.hide();
            qzgjGrid.show();
            action5.setText('看带看');
          } else {
            dkgjGrid.show();
            qzgjGrid.hide();
            action5.setText('看跟进');
          }
        }
        //iconCls: 'blist'
    });

    var action6 = new Ext.Action({
        text: '写带看',
        handler: function(){
            
            var track_win = new Ext.Window({
                title: '写带看',
                floating: true,
                shadow: true,
                draggable: true,
                closable: true,
                modal: true,
                width: 430,
                height: 360,
                layout: 'fit',
                plain: true,
                items: [{
                  xtype:"form",
                  id : 'qzdk_track_win_form',
                  width: 422,
                  height: 326,
                  padding: 10,
                  layout: 'absolute',
                  items:[
                      {
                          xtype: 'label',
                          text: '合同编号',
                          x: 20,
                          y: 10
                      },
                      {
                          xtype: 'label',
                          text: '房源编号',
                          x: 20,
                          y: 40
                      },
                      {
                          xtype: 'label',
                          text: '带看时间',
                          x: 20,
                          y: 70
                      },
                      {
                          xtype: 'label',
                          text: '带看人',
                          x: 30,
                          y: 100
                      },
                      {
                          xtype: 'label',
                          text: '客户名',
                          x: 30,
                          y: 130
                      },
                      {
                          xtype: 'label',
                          text: '接待人',
                          x: 30,
                          y: 160
                      },
                      {
                          xtype: 'label',
                          text: '带看内容',
                          x: 20,
                          y: 190
                      },
                      {
                          xtype: 'textfield',
                          x: 90,
                          y: 10,
                          width: 200,
                          name: 'dkht'
                      },
                      {
                          xtype: 'combo',
                          x: 90,
                          y: 40,
                          width: 200,
                          name: 'fyxx',
                          store: fyxx_store,
                          mode: 'remote',
                          minChars : 2,
                          valueField:'id',
                          displayField:'value',
                          triggerAction:'all'
                      },
                      {
                          xtype: 'datefield',
                          x: 90,
                          y: 70,
                          width: 200,
                          name: 'visit_at',
                          format :'Y-m-d',
                          value: (new Date()).format('Y-m-d')
                      },
                      {
                          xtype: 'textfield',
                          x: 90,
                          y: 100,
                          width: 200,
                          name: 'yg_xm',
                          value: currentUser.login,
                      },
                      {
                          xtype: 'textfield',
                          x: 90,
                          y: 130,
                          width: 200,
                          name: 'qz_xm'
                      },
                      {
                          xtype: 'textfield',
                          x: 90,
                          y: 160,
                          width: 200,
                          name: 'cz_xm'
                      },
                      {
                          xtype: 'textarea',
                          x: 90,
                          y: 190,
                          width: 200,
                          height: 80,
                          name: 'message'
                      }
                  ],
                  buttons:[{
                    text: '保存',
                    handler: function(){
                      var pars = Ext.getCmp("qzdk_track_win_form").getForm().getValues();
                      pars['yg_id']=currentUser.id;
                      pars['qzxx_id']=qzxx_id;
                      pars['fyxx'] = Ext.getCmp('qzdk_track_win_form').getForm().items.items[1].getValue();
                      var now = new Date();
                      pars['create_at']=now.format('Y-m-d H:i:s');
                      
                      new Ajax.Request("/desktop/add_dkgj_qz", { 
                        method: "POST",
                        parameters: pars,
                        onComplete:  function(request) {
                          track_win.close();
                          
                          //reload track window
                          Ext.getCmp('qzxx-view').dkgjStore.baseParams = {id:qzxx_id}
                          Ext.getCmp('qzxx-view').dkgjStore.load();
                        }
                      });
                    }
                  },{
                    text: '取消',
                    handler: function(){
                      track_win.close();
                    }
                  }]
                }]
            });
            
            track_win.show();
            track_win.setZIndex(9020);  
        }
    });


    this.qzgjStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/desktop/get_qzgj'
        }),

        reader: new Ext.data.JsonReader({
          totalProperty: 'results', 
          root: 'rows',             
          fields: [
            {name: 'id'},
            {name: 'qzxx_id',   type: 'string'},             
            {name: 'create_at', type: 'date', dateFormat: 'Y-m-d H:i:s'},
            {name: 'yg_id',   type: 'string'},                     
            {name: 'ygbm',      type: 'string'},             
            {name: 'ygxm',      type: 'string'},             
            {name: 'message',   type: 'string'},             
            {name: 'txsj',      type: 'string', dateFormat: 'Y-m-d H:i:s'},            
            {name: 'txfw',      type: 'string'},             
            {name: 'txnr',      type: 'string'},             
          ]    
        }),
        sortInfo:{field: 'id', direction: "DESC"}
    });
    
    // create the Grid
    var qzgjGrid = new Ext.grid.GridPanel({
        store: this.qzgjStore,
        columns: [
           // {id:'id',header: 'id', width: 20, hidden: true, dataIndex: 'id', sortable: true},
           {header: '跟进信息',   width: 250, sortable: true, dataIndex: 'message'},
           {header: '部门',     width: 50, sortable: true,  dataIndex: 'ygbm'},
           {header: '跟进人',    width: 50, sortable: true,  dataIndex: 'ygxm'},
           {header: '最后更新日期', width: 100, sortable: true,  renderer: Ext.util.Format.dateRenderer('Y-m-d'), dataIndex: 'create_at'}
        ],
        stripeRows: true
        //autoExpandColumn: 'message',
        // config options for stateful behavior
        //stateful: true,
        //stateId: 'grid'        
    });
    
    
    this.dkgjStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/desktop/get_dkgj_qz'
        }),

        reader: new Ext.data.JsonReader({
          totalProperty: 'results', 
          root: 'rows',             
          fields: [
            {name: 'id'},
            {name: 'create_at', type: 'date', dateFormat: 'Y-m-d H:i:s'},
            {name: 'visit_at',  type: 'date', dateFormat: 'Y-m-d H:i:s'},
            {name: 'dkht',      type: 'string'},                     
            {name: 'yg_xm',     type: 'string'},             
            {name: 'qz_xm',     type: 'string'},             
            {name: 'cz_xm',     type: 'string'},             
            {name: 'czbh',          type: 'string'},
            {name: 'message',   type: 'string'}            
          ]    
        }),
        sortInfo:{field: 'id', direction: "DESC"}
    });
    
    // create the Grid
    var dkgjGrid = new Ext.grid.GridPanel({
        store: this.dkgjStore,
        columns: [
           // {id:'id',header: 'id', width: 20, hidden: true, dataIndex: 'id', sortable: true},
           {header: '带看信息',   width: 250, sortable: true, dataIndex: 'message'},
           {header: '带看人',    width: 50, sortable: true,  dataIndex: 'yg_xm'},
           {header: '客户',     width: 50, sortable: true,  dataIndex: 'qz_xm'},
           {header: '接待人',    width: 50, sortable: true,  dataIndex: 'cz_xm'},
           {header: '带看合同',   width: 50, sortable: true,  dataIndex: 'dkht'},
           {header: '出租编号',   width: 50, sortable: true,  dataIndex: 'czbh'},
           {header: '带看时间',   width: 100, sortable: true,  renderer: Ext.util.Format.dateRenderer('Y-m-d'), dataIndex: 'visit_at'}
        ],
        height : 150,
        stripeRows: true
    });
    
    dkgjGrid.hide();
    
    QzxxPanel.superclass.constructor.call(this, {
        id:'qzxx-view',
        layout:'border',
        //title:'Loading...',
        hideMode:'offsets',
        closable:true,   //!!add this to close this panel
        tbar: [{
                text:'全部客源',
                tooltip:'快速选择时间',
                iconCls:'t0',
                split:true,
                handler: this.toggleTime.createDelegate(this, []),
                menu: 
                {
                    id:'qzxx-slelect-menu',
                    cls:'reading-menu',
                    width:100,
                    items: [{
                        text:'全部客源',
                        checked:true,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t0'
                    },{
                        text:'今日新客',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t1'
                    },{
                        text:'最近三天',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t3'
                    },{
                        text:'最近七天',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t7'
                    },{
                        text:'最近半月',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t15'
                    },{
                        text:'最近一月',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t30'
                    },{
                        text:'最近三月',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t90'                   
                    },{
                        text:'最近半年',
                        checked:false,
                        group:'rp-group',
                        checkHandler:this.toggleTime,
                        scope:this,
                        iconCls:'t180'
                    }]
                }
            },
            {
                text:'租购',
                tooltip:'快速选择租购',
                iconCls:'option',
                split:true,
                handler: this.toggleType.createDelegate(this, []),
                menu: {
                    id:'qzxx-option-menu',
                    cls:'option-menu',
                    width:100,
                    items: [{
                        text:'租购',
                        checked:true,
                        group:'op-group',
                        checkHandler:this.toggleType,
                        scope:this,
                        iconCls:'option'
                    },{
                        text:'求租',
                        checked:false,
                        group:'op-group',
                        checkHandler:this.toggleType,
                        scope:this,
                        iconCls:'tz'
                    },{
                        text:'求售',
                        checked:false,
                        group:'op-group',
                        checkHandler:this.toggleType,
                        scope:this,
                        iconCls:'ts'
                    }]
                }
            },
            {
                text:'全部',
                tooltip:'快速选择状态',
                iconCls:'remove',
                split:true,
                handler: this.toggleState.createDelegate(this, []),
                menu: {
                    id:'qzxx-state-menu',
                    cls:'option-menu',
                    width:100,
                    items: [{
                        text:'全部',
                        checked:true,
                        group:'zt-group',
                        checkHandler:this.toggleState,
                        scope:this,
                        iconCls:'option'
                    },{
                        text:'有效',
                        checked:false,
                        group:'zt-group',
                        checkHandler:this.toggleState,
                        scope:this
                    },{
                        text:'有效+预定',
                        checked:false,
                        group:'zt-group',
                        checkHandler:this.toggleState,
                        scope:this
                    },{
                        text:'有效+暂缓',
                        checked:false,
                        group:'zt-group',
                        checkHandler:this.toggleState,
                        scope:this
                    },'-',{
                      text:'预定',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    },{
                      text:'暂缓',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    },{
                      text:'已售',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    },{
                      text:'已租',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    },{
                      text:'我售',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    },{
                      text:'我租',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    },{
                      text:'无效',
                      checked:false,
                      group:'zt-group',
                      checkHandler:this.toggleState,
                      scope:this
                    }]
                }
            },'-', 
            {
                text:'',
                iconCls:'add2',
                split:true,
                handler: function(){
                  add_qzxx();
                },
                menu:{
                  id:'qzxx-plus-menu',
                  items:[{
                      text:'新增客源',
                      scope:this,
                      iconCls:'add2',
                      handler: function(){
                        add_qzxx();
                      }
                  },{
                      text:'修改客源',
                      scope:this,
                      iconCls:'new',
                      handler: function(){
                        add_qzxx(this.gsm);
                      }
                  },{
                      text:'删除客源',
                      checked:true,
                      iconCls:'delete'
                  }]
                }
            },'->', 
            new Ext.form.TextField({
              width:200,
              enableKeyEvents: true, 
              initEvents: function() { 
                var keyPress = function(e){ 
                  if (e.getKey() == e.ENTER) { 
                    Ext.getCmp('qzxx-view').reloadStore();
                  }
                }; 
                this.el.on("keypress", keyPress, this);
              }
            }), 
            {
                text: '查询',
                tooltip:'智能查询',
                iconCls:'search',
                handler:function() {
                  Ext.getCmp('qzxx-view').reloadStore();
                }
            },
            new Ext.PagingToolbar({
              store: this.grid.store,
              pageSize: 15,
              displayInfo: true,
              displayMsg: '{0} - {1} of {2}',
              emptyMsg: "没有找到！",
              prependButtons: true
            })    
        ],
        items: [{
            region:"center",
            layout: 'fit',
            items: this.grid
          },
          {
            region:"north",
            height:70,
            split:true,
            collapsed:true,
            collapseMode:'mini',
            layout: 'absolute',
            id:'qzxx_north_search',           
            items:[{
                xtype: 'form',
                width: 800,
                height: 70,
                layout: 'absolute',
                border: false,
                items: [
                    {
                        xtype: 'label',
                        text: '交易',
                        x: 10,
                        y: 10
                    },
                    {
                        xtype: 'label',
                        text: '状态',
                        x: 120,
                        y: 10
                    },
                    {
                        xtype: 'label',
                        text: '用途',
                        x: 240,
                        y: 10
                    },
                    {
                        xtype: 'label',
                        text: '价格',
                        x: 360,
                        y: 10
                    },
                    {
                        xtype: 'label',
                        text: '-',
                        x: 452,
                        y: 10
                    },
                    {
                        xtype: 'label',
                        text: '-',
                        x: 452,
                        y: 40,
                        width: 10
                    },
                    {
                        xtype: 'label',
                        text: '类型',
                        x: 240,
                        y: 40
                    },
                    {
                        xtype: 'label',
                        text: '日期',
                        x: 10,
                        y: 40
                    },
                    {
                        xtype: 'label',
                        text: '面积',
                        x: 360,
                        y: 40
                    },
                    {
                        xtype: 'combo',
                        x: 40,
                        y: 10,
                        width: 70,
                        name: 'jy',
                        emptyText:'全部',
                        store: cz_store,
                        mode: 'local',
                        valueField:'text',
                        displayField:'text',
                        triggerAction:'all'
                    },
                    {
                        xtype: 'combo',
                        x: 150,
                        y: 10,
                        width: 70,
                        name: 'zt',
                        emptyText:'全部',
                        store: zt_store,
                        mode: 'local',
                        valueField:'text',
                        displayField:'text',
                        triggerAction:'all'
                    },
                    {
                        xtype: 'combo',
                        x: 270,
                        y: 10,
                        width: 70,
                        name: 'yt',
                        emptyText:'全部',
                        store: yt_store,
                        mode: 'local',
                        valueField:'text',
                        displayField:'text',
                        triggerAction:'all'
            
                    },
                    {
                        xtype: 'textfield',
                        x: 390,
                        y: 10,
                        width: 60,
                        name: 'jg1',
                        value: '0'
                    },
                    {
                        xtype: 'textfield',
                        x: 460,
                        y: 10,
                        width: 60,
                        name: 'jg2',
                        emptyText:'不限'
                    },
                    {
                        xtype: 'datefield',
                        x: 40,
                        y: 40,
                        name: 'date1',
                        width: 90,
                        format: 'Y-m-d',
                        value: (new Date()).format('Y-m-d')
                    },
                    {
                        xtype: 'datefield',
                        x: 130,
                        y: 40,
                        name: 'date2',
                        width: 90,
                        format: 'Y-m-d',
                        value: (new Date()).format('Y-m-d')
                    },
                    {
                        xtype: 'combo',
                        x: 270,
                        y: 40,
                        width: 70,
                        name: 'lx',
                        emptyText:'全部',
                        store: lx_store,
                        mode: 'local',
                        valueField:'text',
                        displayField:'text',
                        triggerAction:'all'
                    },
                    {
                        xtype: 'textfield',
                        x: 390,
                        y: 40,
                        width: 60,
                        name: 'mj1',
                        value: '0'
                    },
                    {
                        xtype: 'textfield',
                        x: 460,
                        y: 40,
                        width: 60,
                        name: 'mj2',
                        emptyText:'不限'
                    },
                    {
                        xtype: 'button',
                        x: 550,
                        y: 10,
                        width : 50,
                        height : 50,
                        text : '查找',
                        handler: function(){
                            Ext.getCmp('qzxx-view').reloadStore();
                        }
                    }
                ]
            }]
          },
          {
            region:"south",
            //title:"详细信息",
            height:150,
            split:true,
            //collapsible:true,
            collapseMode:'mini',
            //titleCollapse:true,
            layout:'border',
            items:[
            {
                  region:"center",
                  layout: 'fit',
                  width: 400,
                  items: [qzgjGrid, dkgjGrid]
              },
              {
                  region:"west",
                  layout: 'fit',
                  id: "qzxx_detailPanel",
                  width:300,
                  bodyStyle: {
                    background: '#ffffff',
                    padding: '7px'
                  },
                  html: '请选择一个客源信息'
              },
              {
                  region:"east",
                  //layout:'accordion',
                  id: "speedbuttons",
                  width:50,
                  bodyStyle: {
                    background: '#cccccc',
                    padding: '3px'
                  },
                  items:[
                    new Ext.Button(action1),
                    new Ext.Button(action2),
                    new Ext.Button(action3),
                    new Ext.Button(action5),
                    new Ext.Button(action6)
                  ]                 
            }]
        }]
    });

    this.gsm = this.grid.getSelectionModel();

    this.gsm.on('rowselect', function(sm, index, r){
          qzxx_id = r.id;
          var detailPanel = Ext.getCmp('qzxx_detailPanel');
          qzxxTpl.overwrite(detailPanel.body, r.data);
          
          //reload 
          this.qzgjStore.baseParams = {id:qzxx_id}
          this.qzgjStore.load();
          
          //reload 
          this.dkgjStore.baseParams = {id:qzxx_id}
          this.dkgjStore.load();
              
    }, this, {buffer:250});

    //this.grid.store.on('beforeload', this.qzxxform.clear, this.qzxxform);
    this.grid.store.on('load', function(){ 
        if (qzxx_id==0) 
          Ext.getCmp('qzxx-view').gsm.selectFirstRow();
      }, this.gsm);
      
    this.grid.on('rowdblclick', function(sm, index, r){
        add_qzxx(Ext.getCmp('qzxx-view').gsm);  
    }, this);
    
    if (currentUser.prev_code[6] != 't') {
      Ext.getCmp('qzxx-plus-menu').items.items[2].hide();
    };

    if (currentUser.prev_code[7] != 't') {
      Ext.getCmp('qzxx-plus-menu').items.items[1].setText('查看客源');
    };
};

Ext.extend(QzxxPanel, Ext.Panel, {
    selectFirst: function(){ 
      if (qzxx_id==0) this.gsm.selectFirstRow();
    },
  
    loadFeed : function(feed){
      if (feed == 'qzxxs') {
        Ext.getCmp('qzxx-view').setTitle(feed.text);
      }
    },
    
    reloadStore : function() {
      var btn_0 = Ext.getCmp('qzxx-view').getTopToolbar().items.get(0);
      var btn_1 = Ext.getCmp('qzxx-view').getTopToolbar().items.get(1);
      var btn_2 = Ext.getCmp('qzxx-view').getTopToolbar().items.get(2);
      
      //search Text
      var btn_6 = Ext.getCmp('qzxx-view').getTopToolbar().items.get(6);
      
      
      
      //Advanced Search
      var qzxx_ns = Ext.getCmp('qzxx_north_search');

      if (qzxx_ns.isVisible()) {
        var ns_val = qzxx_ns.items.items[0].getForm().getValues();
        paras = {time:btn_0.text, jylx:btn_1.text, zt:btn_2.text, search:btn_6.getValue(), ygxm:currentUser.login,  start:0, limit:15, date1:ns_val.date1, date2:ns_val.date2, jg1:ns_val.jg1, jg2:ns_val.jg2, mj1:ns_val.mj1, mj2:ns_val.mj2, jy:ns_val.jy, lx:ns_val.lx, yt:ns_val.yt, zt:ns_val.zt} 
      } else {
        var paras = {time:btn_0.text, jylx:btn_1.text, zt:btn_2.text, search:btn_6.getValue(), ygxm:currentUser.login,  start:0, limit:15};
      }
      
      //set seleted qzxx_id  to null
      qzxx_id = 0;
      this.grid.loadData(paras);
      
      //reald qzgj
      this.qzgjStore.baseParams = {id:qzxx_id}
      this.qzgjStore.load();
      
    },
    
    toggleTime : function(m, pressed){
      
        if(!m){ // cycle if not a menu item click
            var items = Ext.menu.MenuMgr.get('qzxx-slelect-menu').items.items;
            
            for (var k=0; k < items.size(); k++) {
              if (items[k].checked) {
                if (items[(k+1)%items.size()].itemCls == 'x-menu-sep') k = k+1;
                items[(k+1)%items.size()].setChecked(true);
                break;
              } 
            }
            
            return;
        };
        
        if(pressed){
            //var preview = this.grid;
            var btn = Ext.getCmp('qzxx-view').getTopToolbar().items.get(0);
            //btn.setIconClass('add');
            btn.setText(m.text);
            
            switch(m.text){
                case '全部客源':
                    btn.setIconClass('t0');
                    break;              
                case '今日新客':
                    btn.setIconClass('t1');
                    break;
                case '最近三天':
                    btn.setIconClass('t3');
                    break;
                case '最近七天':
                    btn.setIconClass('t7');
                    break;    
            };
            
            //reload store
            this.reloadStore();
            
            
        }
        
    },

    toggleType : function(m, pressed){
        if(!m){ // cycle if not a menu item click
            var items = Ext.menu.MenuMgr.get('qzxx-option-menu').items.items;
            for (var k=0; k < items.size(); k++) {
              if (items[k].checked) {
                if (items[(k+1)%items.size()].itemCls == 'x-menu-sep') k = k+1;
                items[(k+1)%items.size()].setChecked(true);
                break;
              } 
            }
            return;
        }
        
        if(pressed){
            var btn = Ext.getCmp('qzxx-view').getTopToolbar().items.get(1);
            //btn.setIconClass('option');
            btn.setText(m.text);
            
            switch(m.text){
                case '租购':
                    btn.setIconClass('option');
                    break;              
                case '出租':
                    btn.setIconClass('tz');
                    break;
                case '出售':
                    btn.setIconClass('ts');
                    break;
            };
            
            //reload store
            this.reloadStore();
            
            //reald qzgj
            this.qzgjStore.baseParams = {id:qzxx_id}
            this.qzgjStore.load();
            
        }
    },

    toggleState : function(m, pressed){
        if(!m){ // cycle if not a menu item click
            var items = Ext.menu.MenuMgr.get('qzxx-state-menu').items.items;
            for (var k=0; k < items.size(); k++) {
              if (items[k].checked) {
                if (items[(k+1)%items.size()].itemCls == 'x-menu-sep') k = k+1;
                items[(k+1)%items.size()].setChecked(true);
                break;
              } 
            }
            return;
        }
        
        if(pressed){
            var btn = Ext.getCmp('qzxx-view').getTopToolbar().items.get(2);
            //btn.setIconClass('option');
            btn.setText(m.text);
            
            switch(m.text){
                case '租购':
                    btn.setIconClass('option');
                    break;              
                case '求租':
                    btn.setIconClass('tz');
                    break;
                case '求购':
                    btn.setIconClass('ts');
                    break;
            };
            
            //reload store
            this.reloadStore();
        }
    }

});

Ext.reg('appqzxxpanel', QzxxPanel);